<?php
/**
 * Smarty plugin
 * @package Smarty
 * @subpackage plugins
 */


/**
 * Smarty i18n modifier plugin
 *
 * Type:     modifier<br>
 * Name:     i18n<br>
 * Date:     Dec 3, 2003
 * Purpose:  translate a value to a specified language
 * Input:    string to translate
 * Example:  {$var|i18n:"en"}
 * @author   Grinchisihn Vitaliy
 * @version 1.0
 * @param string
 * @param string
 * @return string
 */
function smarty_modifier_i18n($string, $language="")
{
	
 	$translates=unserialize(file_get_contents(LANGUAGES_FILE));
	
	# getting main language
	$main_lang=(isset($translates["main_language"]) && !empty($translates["main_language"]))?$translates["main_language"]:"";
	
	$lang="";
	
	if(!empty($language)){
		$lang=$language;
	}elseif(isset($_SESSION["lang"])){
		$lang=$_SESSION["lang"];
	}
	if(!empty($lang)){
		if(!empty($translates["languages"][$string][$lang])){
			return $translates["languages"][$string][$lang];
		}else{
			return $string;
		}
	}else{
		return $string;
	}
}

/* vim: set expandtab: */

?>
